<?php

namespace app\common\business;

use app\common\model\mysql\GoodsSku as GoodsSkuModel;
use think\Exception;

class GoodsSku extends BaseBus
{
    public $Model = null;
    public function __construct()
    {
        $this->Model = new GoodsSkuModel();
    }

    public function saveAll($data)
    {
        if (!$data['skus']) {
            return false;
        }
        foreach ($data['skus'] as $value) {
            $insertData[] = [
                'goods_id' => $data['goods_id'],
                'specs_value_ids' => $value['propvalnames']['propvalids'],
                'price' => $value['propvalnames']['skuSellPrice'],
                'cost_price' => $value['propvalnames']['skuMarketPrice'],
                'stock' => $value['propvalnames']['skuStock']
            ];
        }
//        dump($insertData);
//        exit();

        try {
            $res = $this->Model->saveAll($insertData);
            return $res->toArray();
        } catch (\Exception $e) {
            throw new Exception("新增失败", $e->getMessage());
//            echo $e->getMessage();
        }

    }
}